package Mysql

// Databases 为数据库初始化目录

import (
	"fmt"
	"gorm.io/driver/mysql"
	"gorm.io/gorm"
	"gorm.io/gorm/logger"
	"selfService/tool"
)

var DB *gorm.DB

var Config *tool.Config

func init() {
	var err error
	Config = tool.GetConf()
	database := Config.Database
	//conn := database.User + ":" + database.Password + "@tcp(" + database.Host + ":" + database.Port + ")/" + database.DbName + "?charset=" + database.Charset
	//"root:123456@tcp(39.106.133.45:3306)/yaowan?charset=utf8mb4&parseTime=True&loc=Local"
	DB, err = gorm.Open(mysql.Open(database.Url), &gorm.Config{
		Logger: logger.Default.LogMode(logger.Info),
		//SkipDefaultTransaction: true,	//禁用默认事务
		PrepareStmt: true, //缓存预编译语句
	})

	if err != nil {
		fmt.Printf("mysql connect error %v", err)
	}
	if DB.Error != nil {
		fmt.Printf("database error %v", DB.Error)
	}
}
